import 'package:flutter/material.dart';
import './common/touch_callback.dart';

class Search extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SearchState();
  }
}

class SearchState extends State<Search> {
  FocusNode focusNode = new FocusNode(); //焦点获取
  _getText(String text) {
    return TouchCallBack(
      child: Text(
        text,
        style: TextStyle(fontSize: 14, color: Colors.green),
      ),
      onPressed: () {},
      isfeed: false,
    );
  }

  _requestFocus() {
    FocusScope.of(context).requestFocus(focusNode);
    return focusNode;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        margin: EdgeInsets.only(top: 25),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Stack(
              children: <Widget>[
                TouchCallBack(
                    child: Container(
                      height: 45,
                      margin: EdgeInsets.only(left: 12, right: 10),
                      child: Icon(Icons.chevron_left),
                    ),
                    onPressed: () {
                      Navigator.pop(context);
                    }),
                Container(
                  alignment: Alignment.centerLeft,
                  height: 45,
                  margin: EdgeInsets.only(
                    left: 50,
                    right: 10,
                  ),
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                    width: 1,
                    color: Colors.green,
                  ))),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                          child: TextField(
                        focusNode: _requestFocus(),
                        style: TextStyle(
                          color: Colors.black,
                          fontSize: 16,
                        ),
                        onChanged: (String text) {},
                        decoration: InputDecoration(
                            hintText: '搜索', border: InputBorder.none),
                      )),
                      Container(
                        margin: EdgeInsets.only(right: 10),
                        child: Icon(
                          Icons.mic,
                          color: Color(0xffaaaaaa),
                        ),
                      )
                    ],
                  ),
                )
              ],
            ),
            Container(
              margin: EdgeInsets.all(20),
              child: Text(
                '搜索指定文章',
                style: TextStyle(fontSize: 16, color: Color(0xffb5b5b5)),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(left: 30, right: 30, bottom: 30),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  _getText('朋友圈'),
                  _getText('文章'),
                  _getText('公众号'),
                ],
              ),
            ),
            Padding(
              padding: EdgeInsets.only(left: 30, right: 30),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  _getText('小程序'),
                  _getText('音乐'),
                  _getText('表情'),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
